home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / brlmon.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  4.8 KB  |  138 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Provides a graphical braille display at the top of the screen.
  5. This is mainly for debugging and for demonstrations.'''
  6. __id__ = '$Id: brlmon.py 3882 2008-05-07 18:22:10Z richb $'
  7. __version__ = '$Revision: 3882 $'
  8. __date__ = '$Date: 2008-05-07 14:22:10 -0400 (Wed, 07 May 2008) $'
  9. __copyright__ = 'Copyright (c) 2005-2008 Sun Microsystems Inc.'
  10. __license__ = 'LGPL'
  11. import gtk
  12. DOT_7 = '@'
  13. DOT_8 = '\x80'
  14. DOTS_78 = '\xc0'
  15. NORMAL = " size='xx-large'"
  16. CURSOR_CELL_EMPTY = " background='black'" + " weight='ultrabold'" + " style='italic'"
  17. CURSOR_CELL = " background='white'" + " weight='ultrabold'" + " style='italic'"
  18. ATTRIBUTE_7 = " underline='low'"
  19. ATTRIBUTE_8 = " underline='error'"
  20. ATTRIBUTE_78 = " underline='double'"
  21.  
  22. class BrlMon(gtk.Window):
  23.     """Displays a GUI braille monitor that mirrors what is being
  24.     shown on the braille display.  This currently needs a lot of
  25.     work, but it is a start.  TODO's include doing a better job of
  26.     docking it at the top of the display (e.g., make all other
  27.     windows move out from underneath it), doing better highlighting of
  28.     the cursor cell, allowing the font to be set, and perhaps allowing
  29.     clicks to simulate cursor routing keys."""
  30.     
  31.     def __init__(self, numCells = 32, cellWidth = 25, cellHeight = 50):
  32.         '''Create a new BrlMon.
  33.  
  34.         Arguments:
  35.         - numCells: how many braille cells to make
  36.         - cellWidth: width of each cell in pixels
  37.         - cellHeight: height of each cell in pixels
  38.         '''
  39.         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
  40.         self.set_title('Braille Monitor')
  41.         self.set_default_size(cellWidth * numCells, cellHeight)
  42.         hbox = gtk.HBox(True)
  43.         self.add(hbox)
  44.         self.cellFrames = []
  45.         self.cellLabels = []
  46.         i = 0
  47.         while i < numCells:
  48.             frame = gtk.Frame()
  49.             frame.set_shadow_type(gtk.SHADOW_OUT)
  50.             label = gtk.Label(' ')
  51.             label.set_use_markup(True)
  52.             frame.add(label)
  53.             hbox.add(frame)
  54.             self.cellFrames.append(frame)
  55.             self.cellLabels.append(label)
  56.             i += 1
  57.         self.set_property('accept-focus', False)
  58.         self.connect_after('check-resize', self.onResize)
  59.  
  60.     
  61.     def onResize(self, obj):
  62.         '''Tell the window to be a dock and set its struts, which I
  63.         thinks means to attempt to glue it somewhere on the display.
  64.         '''
  65.         screen_width = gtk.gdk.screen_width()
  66.         (window_width, window_height) = self.window.get_size()
  67.         if window_width < screen_width:
  68.             x = (screen_width - window_width) / 2
  69.         else:
  70.             x = 0
  71.         self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK)
  72.         self.window.property_change(gtk.gdk.atom_intern('_NET_WM_STRUT_PARTIAL', False), gtk.gdk.atom_intern('CARDINAL', False), 32, gtk.gdk.PROP_MODE_REPLACE, [
  73.             0,
  74.             0,
  75.             window_height,
  76.             0,
  77.             0,
  78.             0,
  79.             0,
  80.             0,
  81.             0,
  82.             screen_width - 1,
  83.             0,
  84.             0])
  85.         self.move(x, 0)
  86.  
  87.     
  88.     def writeText(self, cursorCell, string, mask = None):
  89.         '''Display the given text and highlight the given
  90.         cursor cell.  A cursorCell of 0 means no cell has
  91.         the cursor.
  92.  
  93.         Arguments:
  94.         - cursorCell: 1-based index of cell with cursor
  95.         - string: len must be <= num cells.
  96.         '''
  97.         
  98.         try:
  99.             string = string.decode('UTF-8')
  100.         except:
  101.             string = ''
  102.  
  103.         for i in range(0, len(string)):
  104.             if string[i] == '<':
  105.                 char = '<'
  106.             elif string[i] == '&':
  107.                 char = '&'
  108.             elif string[i] == '\t':
  109.                 char = '$t'
  110.             else:
  111.                 char = string[i]
  112.             markup = NORMAL
  113.             if i == cursorCell - 1:
  114.                 if string[i] == ' ':
  115.                     markup += CURSOR_CELL_EMPTY
  116.                 else:
  117.                     markup += CURSOR_CELL
  118.                 self.cellFrames[i].set_shadow_type(gtk.SHADOW_IN)
  119.             else:
  120.                 self.cellFrames[i].set_shadow_type(gtk.SHADOW_OUT)
  121.             if mask:
  122.                 if mask[i] == DOTS_78:
  123.                     markup += ATTRIBUTE_78
  124.                 elif mask[i] == DOT_7:
  125.                     markup += ATTRIBUTE_7
  126.                 elif mask[i] == DOT_8:
  127.                     markup += ATTRIBUTE_8
  128.                 
  129.             
  130.             self.cellLabels[i].set_markup('<span' + markup + '>%s</span>' % char)
  131.         
  132.         for i in range(len(string), len(self.cellFrames)):
  133.             self.cellLabels[i].set_text(' ')
  134.             self.cellFrames[i].set_shadow_type(gtk.SHADOW_OUT)
  135.         
  136.  
  137.  
  138.